package com.masterclient.app.businessmodule.minemodule.index.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;

import com.airbnb.lottie.LottieAnimationView;
import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.bean.personal.MedalItemBean;
import com.masterclient.app.R;

import java.util.List;

public class PersonMedalAdapter extends BaseQuickAdapter<MedalItemBean, BaseViewHolder> {

    private Context mContext;
    private PersonMedalAdapterListener iPersonMedalAdapterListener;

    public void setPersonMedalAdapterListener(PersonMedalAdapterListener iPersonMedalAdapterListener) {
        this.iPersonMedalAdapterListener = iPersonMedalAdapterListener;
    }

    public PersonMedalAdapter(Context context, int layoutResId, @Nullable List<MedalItemBean> data) {
        super(layoutResId, data);
        this.mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, MedalItemBean item) {
        LottieAnimationView imageView = helper.getView(R.id.medal_image_view);

        String json = "new_small.json";
        if (item.getMedal_special_effects()!=null && item.getMedal_special_effects().equals("1")) {
            json = "super_small.json";
        }
        LottieComposition composition = LottieComposition.Factory.fromFileSync(mContext,   json);
        imageView.cancelAnimation();
        imageView.setProgress(0);
        imageView.setRepeatCount(-1);
        imageView.setRepeatMode(LottieDrawable.RESTART);
        imageView.setComposition(composition);
        imageView.playAnimation();

//        GlideUtil.displayImageFitCenter(mContext,item.getSh_medal_image(),imageView, 0,ScreenUtils.dp2px(99), ScreenUtils.dp2px(23));
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (iPersonMedalAdapterListener != null) {
                    iPersonMedalAdapterListener.onClickItem(item);
                }
            }
        });
    }


    public interface PersonMedalAdapterListener {
        void onClickItem(MedalItemBean itemBean);
    }

}
